﻿@inherits BaseComponentBase
@attribute [Authorize]
@attribute [IgnoreRolePermission]
@using Masa.Blazor.Presets
@using Microsoft.AspNetCore.Authorization;
@using ThingsGateway.Admin.Blazor
@using ThingsGateway.Core.Extension
@namespace ThingsGateway.Gateway.Blazor
@inject UserResoures UserResoures;


<MRow>
    <MCol Md=3 Cols=12>
        <MCard Height=140 Elevation=1 Rounded=true Class="ma-2">
            <MCardText>
                <MRow Class="max-height" NoGutters>
                    <MCol>
                        <span>@AppService.I18n.T("采集设备") 📊</span>
                        <h5 class="my-1">@(_collectDeviceCount)</h5>
                    </MCol>
                    <MCol Class="block-center">
                        <MECharts Height=100 Width="@("100%")" Class="mb-1" Option=_collectDeviceChart></MECharts>
                    </MCol>
                </MRow>
            </MCardText>
        </MCard>
    </MCol>

    <MCol Md=3 Cols=12>
        <MCard Height=140 Elevation=1 Rounded=true Class="ma-2">
            <MCardText>
                <MRow Class="max-height" NoGutters>
                    <MCol>
                        <span>@AppService.I18n.T("业务设备") 📊</span>
                        <h5 class="my-1">@(_businessDeviceCount)</h5>
                    </MCol>
                    <MCol Class="block-center">
                        <MECharts Height=100 Width="@("100%")" Class="mb-1" Option=_businessDeviceChart></MECharts>
                    </MCol>
                </MRow>
            </MCardText>
        </MCard>
    </MCol>

    <MCol Md=3 Cols=12>
        <MCard Height=140 Elevation=1 Rounded=true Class="ma-2">
            <MCardText>
                <MRow Class="max-height" NoGutters>
                    <MCol>
                        <span>@AppService.I18n.T("变量") 📊</span>
                        <h5 class="my-1">@(_variableCount)</h5>
                    </MCol>
                    <MCol Class="block-center">
                        <MECharts Height=100 Width="@("100%")" Class="mb-1" Option=_variableChart></MECharts>
                    </MCol>
                </MRow>
            </MCardText>
        </MCard>
    </MCol>


    <MCol Md=3 Cols=12>
        <MCard Height=140 Elevation=1 Rounded=true Class="ma-2">
            <MCardText>
                <MRow Class="max-height" NoGutters>
                    <MCol>
                        <span>@AppService.I18n.T("报警")</span>
                        <h5 class="my-1">@(_alarmCount)</h5>
                    </MCol>
                </MRow>
            </MCardText>
        </MCard>
    </MCol>

</MRow>
<MCard MinHeight=120 Rounded=true Elevation=1 Class="ma-2 mt-4">
    <MCardSubtitle Class="text-subtitle-1">
        @AppService.I18n.T("快捷方式")
    </MCardSubtitle>
    <MDivider></MDivider>
    <MRow Class="pa-4" NoGutters Align="AlignTypes.Center" Justify="JustifyTypes.Start">
         @foreach (var menu in UserResoures.UserWorkbenchOutputs ?? new())
        {
            <MButton Text Href=@menu.Href
                      Target=@((menu.MenuType == MenuTypeEnum.MENU || menu.MenuType == MenuTypeEnum.IFRAME) ? "_self" : "_blank") Class="ma-2 text-subtitle px-2">
                 <MIcon Left Size="30" Color="primary">@menu.Icon</MIcon>
                    @menu.Title
            </MButton>
        }
    </MRow>

</MCard>

<MCard MinHeight=500 Rounded=true Elevation=1 Class="ma-2 mt-4">
    <MCardSubtitle Class="text-subtitle-1">
        @AppService.I18n.T("CPU曲线")
    </MCardSubtitle>
    <MDivider></MDivider>
    <MRow Class="pa-4" NoGutters Align="AlignTypes.Center" Justify="JustifyTypes.Start">

         <MECharts @ref=hardwareInfoECharts Option=hardwareInfoEChartsOption Width="@("100%")" MinHeight="400"></MECharts>

     </MRow>
 </MCard>

 <MRow NoGutters>
    <MCol Md=6 Cols="12">
        <MCard Style="height:500px;overflow-y:auto;overflow-x:hidden" Elevation=1 Rounded=true Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                @AppService.I18n.T("Rpc日志")
            </MCardSubtitle>
            <MDivider></MDivider>
            <MTimeline AlignTop Dense>
                @foreach (var item in _rpcLogs ?? new())
                {
                    <MTimelineItem Color="primary"
                                      Small>
                     <MRow Class="pt-1">
                         <MCol Cols="4">
                             <span class="text-caption">@item.LogTime.ToDefaultDateTimeFormat(AppService.TimezoneOffset)</span>
                            </MCol>
                            <MCol>
                                <div class="text-body-1">@item.OperateObject</div>
                                <div class="text-caption">@item.OperateSource</div>
                            </MCol>
                        </MRow>
                    </MTimelineItem>

                }

            </MTimeline>
        </MCard>
    </MCol>
    <MCol Md=6 Cols="12">
        <MCard Style="height:500px;overflow-y:auto;overflow-x:hidden" Elevation=1 Rounded=true Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                @AppService.I18n.T("后台日志")
            </MCardSubtitle>
            <MDivider></MDivider>
            <MTimeline AlignTop Dense>
                @foreach (var item in _backendLogs ?? new())
                {
                    <MTimelineItem Color="primary"
                                      Small>
                     <MRow Class="pt-1">
                         <MCol Cols="4">
                             <span class="text-caption">@item.LogTime.ToDefaultDateTimeFormat(AppService.TimezoneOffset)</span>
                            </MCol>
                            <MCol>
                                <div class="text-body-1">@item.LogLevel</div>
                                <div class="text-caption">@item.LogMessage</div>
                            </MCol>
                        </MRow>
                    </MTimelineItem>

                }

            </MTimeline>
        </MCard>
    </MCol>
</MRow>

<MRow NoGutters>
    <MCol Md=6 Cols="12">
        <MCard Style="height:500px;overflow-y:auto;overflow-x:hidden" Elevation=1 Rounded=true Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                @AppService.I18n.T("访问日志")
            </MCardSubtitle>
            <MDivider></MDivider>
            <MTimeline AlignTop Dense>
                @foreach (var item in _sysVisitLogs ?? new())
                {
                    <MTimelineItem Color="primary"
                                      Small>
                     <MRow Class="pt-1">
                         <MCol Cols="4">
                             <span class="text-caption">@item.OpTime.ToDefaultDateTimeFormat(AppService.TimezoneOffset)</span>
                            </MCol>
                            <MCol>
                                <div class="text-body-1">@item.Name</div>
                                <div class="text-caption">@item.OpIp</div>
                            </MCol>
                        </MRow>
                    </MTimelineItem>

                }

            </MTimeline>
        </MCard>
    </MCol>
    <MCol Md=6 Cols="12">
        <MCard Style="height:500px;overflow-y:auto;overflow-x:hidden" Elevation=1 Rounded=true Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                @AppService.I18n.T("操作日志")
            </MCardSubtitle>
            <MDivider></MDivider>
            <MTimeline AlignTop Dense>
                @foreach (var item in _sysOperateLogs ?? new())
                {
                    <MTimelineItem Color="primary"
                                      Small>
                     <MRow Class="pt-1">
                         <MCol Cols="4">
                             <span class="text-caption">@item.OpTime.ToDefaultDateTimeFormat(AppService.TimezoneOffset)</span>
                            </MCol>
                            <MCol>
                                <div class="text-body-1">@item.Name</div>
                                <div class="text-caption">@item.OpIp</div>
                            </MCol>
                        </MRow>
                    </MTimelineItem>

                }

            </MTimeline>
        </MCard>
    </MCol>
</MRow>


